package cn.est.controller;

import cn.est.constants.Constants;
import cn.est.dto.ClassfyDto;
import cn.est.dto.Result;
import cn.est.service.ClassifyService;
import cn.est.utils.RedisUtil;
import cn.est.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName HomeController
 * @Description TODO
 * @Author yaozhaobao
 * @Date 2021/4/13 9:57
 * @Version 1.0
 **/
@RestController
@Api
@RequestMapping("/api/home")
public class HomeController {



    @Autowired
    ClassifyService classifyService;

    @Autowired
    RedisUtil redisUtil;


    @ApiOperation(value="首页的商品分类",notes = "首页的商品分类树,包含分类，品牌，型号信息")
    @GetMapping(value="/classifyTree", produces = "application/json")
    public Result<List<ClassfyDto>> list(){
        List<ClassfyDto> result= (List<ClassfyDto>) redisUtil.get(Constants.Home.ClASSFYLIST);
        if(result==null) {
            System.out.println("执行了数据库查询");
            result = classifyService.queryClassfytree();
            redisUtil.set(Constants.Home.ClASSFYLIST,result,Constants.Home.CLASSFYLIST_TIME);
        }
        return ResultUtils.returnDataSuccess(result);
    }







}
